package me.buick.util.jmeter.snmpprocessvisualizers;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.accessibility.AccessibleContext;
import javax.swing.JPopupMenu;


public class SNMPProcessPlotterPanel extends SNMPProcessBorderedComponent {
    SNMPProcessPlotter plotter;

    public SNMPProcessPlotterPanel(String labelStr, SNMPProcessPlotter.Unit unit, boolean collapsible) {
	super(labelStr, new SNMPProcessPlotter(unit), collapsible);

	this.plotter = (SNMPProcessPlotter)comp;

	init();
    }

    public SNMPProcessPlotterPanel(String labelStr) {
	super(labelStr, null);

	init();
    }

    public SNMPProcessPlotter getPlotter() {
	return this.plotter;
    }

    public void setPlotter(SNMPProcessPlotter plotter) {
	this.plotter = plotter;
	setComponent(plotter);
    }

    private void init() {
	setFocusable(true);

	addMouseListener(new MouseAdapter() {
	    public void mousePressed(MouseEvent e) {
		requestFocusInWindow();
	    }
	});
    }

    public JPopupMenu getComponentPopupMenu() {
	return (getPlotter() != null)? getPlotter().getComponentPopupMenu() : null;
    }

    public AccessibleContext getAccessibleContext() {
	if (accessibleContext == null) {
	    accessibleContext = new AccessiblePlotterPanel();
	}
	return accessibleContext;
    }

    protected class AccessiblePlotterPanel extends AccessibleJComponent {
        public String getAccessibleName() {
	    String name = null;
	    if (getPlotter() != null) {
		name = getPlotter().getAccessibleContext().getAccessibleName();
	    }
	    if (name == null) {
		name = super.getAccessibleName();
	    }
	    return name;
	}
    }
}